var path="http://localhost:8080/ddln-seek";
var path2="http://localhost:8080/ddln-admin"
var goods_img_main="";
var goods_img_main2="";
var goods_img_max="";
var goods_img_min="";


var catId = localStorage["catId"];

$(function(){
	$("#addGoods").click(function(){
		var goodsForm=$("#goodsForm");
		goodsForm.attr("action",path2+"/admin/goods/addGoods"); 
		$("#goods_img_main").val(goods_img_main);
		$("#goods_img_main2").val(goods_img_main2);
		$("#goods_img_list").val(goods_img_max+":"+goods_img_min); 
		$("#goods_img_detaillist").val(getImageUrl());   
		var t = $('form').serialize();
	            
	    $.ajax({ 
			type:"POST",
			url:path2+"/admin/goods/addGoods", 
			data:t,      
			dataType:"json",
			success:function(data){  
				
				if(data.success=="true"){
					alert("添加成功"); 
					location.href="admin-addgoods.html";          
				}
			},
			error:function(data){ 
				//alert("对不起，加载失败");
			}
		});
		
	});
});  
    
$(function() {     
	$.ajax({ 
		type:"POST",
		url:path+"/seek/goodsBrand/listEs_GoodsBrandAll", 
		data:{}, 
		dataType:"json",
		success:function(data){  
		   var goods_brand=$("#goods_brand_id");
			
			for (var i = 0; i < data.data.length; i++) { 
				
				var s=$('<option value="'+data.data[i].brand_id+'">'+data.data[i].name+'</option>  ');
				
				goods_brand.append(s);
			}  
		},
		error:function(data){ 
			//alert("对不起，加载失败");
		}
	});
	
	$.ajax({ 
		type:"POST",
		url:path+"/seek/goodsCat/getCatById", 
		data:{"catId":catId}, 
		dataType:"json",
		success:function(data){  
		   $("#goods_catId").val(catId);
		   $("#goods_catName").text(data.data.name); 
		},
		error:function(data){ 
			//alert("对不起，加载失败");
		}
	});
	
    $("#file_upload").uploadify({   
    	'height'        : 27, 
    	'width'         : 320,   
    	'buttonText'    : '添加标准图',
        'swf'           : 'static/uploadify/uploadify.swf',
        'uploader'      : 'http://localhost:8080/ddln-admin/admin/upload/uploadImage',
        'auto'          : false,    
        'fileTypeExts'  : '*.gif; *.jpg; *.png',
        'onUploadStart' : function(file) {                                                                                                    
        	 
        	//alert('Starting to upload ' + file.path);
        	$("#file_upload").uploadify("settings", "formData");
        },
        'onUploadSuccess' : function(file, data, response) { 
        	var json = eval('(' +  data.toString() + ')');
        	goods_img_min+=json.data+",";  
            //alert('The file ' + file.name + ' was successfully uploaded with a response of ' + response + ':' + data);
        },'onSelect' : function(file) {
            //alert('The file ' + $("#file_upload").val() + ' 888was added to the queue.');          
        }  
    });
    
    $("#file_upload2").uploadify({   
    	'height'        : 27, 
    	'width'         : 320,   
    	'buttonText'    : '添加大图',
        'swf'           : 'static/uploadify/uploadify.swf',
        'uploader'      : 'http://localhost:8080/ddln-admin/admin/upload/uploadImage',
        'auto'          : false,    
        'fileTypeExts'  : '*.gif; *.jpg; *.png',
        'onUploadStart' : function(file) { 
        	 
        	//alert('Starting to upload ' + file.path);
        	//$("#file_upload").uploadify("settings", "formData");
        },
        'onUploadSuccess' : function(file, data, response) { 
        	var json = eval('(' +  data.toString() + ')');
        	goods_img_max+=json.data+",";
            //alert('The file ' + file.name + ' was successfully uploaded with a response of ' + response + ':' + data);
        },'onSelect' : function(file) {
            //alert('The file ' + $("#file_upload").val() + ' 888was added to the queue.');          
        }  
    });
    $("#file_upload3").uploadify({      
    	'multi'         : false, 
    	'height'        : 27,  
    	'width'         : 320,   
    	'buttonText'    : '显示副图片',
        'swf'           : 'static/uploadify/uploadify.swf',
        'uploader'      : 'http://localhost:8080/ddln-admin/admin/upload/uploadImage',
        'auto'          : false,    
        'fileTypeExts'  : '*.gif; *.jpg; *.png',
        'onUploadStart' : function(file) { 
        	 
        	//alert('Starting to upload ' + file.path);
        	//$("#file_upload").uploadify("settings", "formData");
        },
        'onUploadSuccess' : function(file, data, response) { 
        	var json = eval('(' +  data.toString() + ')');
        	goods_img_main2=json.data; 
            //alert('The file ' + file.name + ' was successfully uploaded with a response of ' + response + ':' + data);
        },'onSelect' : function(file) {
            //alert('The file ' + $("#file_upload").val() + ' 888was added to the queue.');          
        }  
    });
    $("#file_upload4").uploadify({   
    	'multi'         : false,
    	'height'        : 27, 
    	'width'         : 320,   
    	'buttonText'    : '显示主图片',
        'swf'           : 'static/uploadify/uploadify.swf',
        'uploader'      : 'http://localhost:8080/ddln-admin/admin/upload/uploadImage',
        'auto'          : false,    
        'fileTypeExts'  : '*.gif; *.jpg; *.png',
        'onUploadStart' : function(file) { 
        	 
        	//alert('Starting to upload ' + file.path);
        	//$("#file_upload").uploadify("settings", "formData");
        },
        'onUploadSuccess' : function(file, data, response) { 
        	var json = eval('(' +  data.toString() + ')');
        	goods_img_main=json.data;           
            //('The file ' + file.name + ' was successfully uploaded with a response of ' + response + ':' + data);
        },'onSelect' : function(file) {
            //alert('The file ' + $("#file_upload").val() + ' 888was added to the queue.');          
        }  
    });
});